package com.zking.frame;

import com.zking.utils.Tool工具;

import javax.swing.*;
import javax.swing.border.MatteBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/*首页*/
public class HomePage {

	private JPanel jPanel ,jPanel2,jPanel3;
	private JLabel homePageJLabel, orderJLabel, myJLabel;// ???????????????????

	public HomePage(JFrame a) {

		a.dispose();

		JFrame jFrame = Tool工具.getJFrame();

		jPanel3 = new JPanel();
		jPanel3.setBounds(0, 0, 645, 900);
		jPanel3.setBackground(Color.white);
		jPanel3.setLayout(null);

		//添加背景图片
		ImageIcon icon = new ImageIcon(HomePage.class.getResource("jf.jpg"));
		JLabel jLabel = new JLabel(icon);
		jLabel.setBounds(0,0,645,900);
		jPanel3.add(jLabel,-1);

		//开始默认选中首页
		jPanel = Tool工具.getJPanelHomePage(jFrame);
		jPanel3.add(jPanel,0);



		jPanel2 = new JPanel();
		jPanel2.setBounds(0, 900, 645, 60);
		jPanel2.setLayout(null);
		jPanel2.setBackground(Color.white);
		jFrame.add(jPanel2, 0);

		// 使用点击事件重新获取首页
		homePageJLabel = new JLabel("首页", 0);
		homePageJLabel.setBounds(50, 5, 110, 50);
		homePageJLabel.setFont(new Font("黑体", Font.BOLD, 20));
		homePageJLabel.setBorder(new MatteBorder(2, 2, 2, 2, new Color(254, 253, 129)));
		homePageJLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
		homePageJLabel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 1) {
					// 获取首页
					jPanel3.removeAll();
					jPanel = Tool工具.getJPanelHomePage(jFrame);
					jPanel3.add(jPanel,0);
					//添加背景
					ImageIcon icon = new ImageIcon(HomePage.class.getResource("jf.jpg"));
					JLabel jLabel = new JLabel(icon);
					jLabel.setBounds(0,0,645,900);
					jPanel3.add(jLabel,-1);
					jPanel3.repaint();
					jPanel3.revalidate();
				}
			}
		});
		jPanel2.add(homePageJLabel);

		orderJLabel = new JLabel("订单", 0);
		orderJLabel.setBounds(260, 5, 110, 50);
		orderJLabel.setFont(new Font("黑体", Font.BOLD, 20));
		orderJLabel.setBorder(new MatteBorder(2, 2, 2, 2, new Color(254, 253, 129)));
		orderJLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
		orderJLabel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 1) {
					// 获取订单页面
					jPanel3.removeAll();
					jPanel = Tool工具.getJPanelOrder(jFrame);
					jPanel3.add(jPanel,0);
					//添加背景
					ImageIcon icon = new ImageIcon(HomePage.class.getResource("jf.jpg"));
					JLabel jLabel = new JLabel(icon);
					jLabel.setBounds(0,0,645,900);
					jPanel3.add(jLabel,-1);
					jPanel3.repaint();
					jPanel3.revalidate();
				}
			}
		});
		jPanel2.add(orderJLabel);


		myJLabel = new JLabel("我的", 0);
		myJLabel.setBounds(470, 5, 110, 50);
		myJLabel.setFont(new Font("黑体", Font.BOLD, 20));
		myJLabel.setBorder(new MatteBorder(2, 2, 2, 2, new Color(254, 253, 129)));
		myJLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
		myJLabel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 1) {
					// 获取我的页面
					jPanel3.removeAll();
					Tool工具 t = new Tool工具();
					jPanel = Tool工具.getJPanelMy(jFrame,t.getName());
					jPanel3.add(jPanel,0);
					//添加背景
					ImageIcon icon = new ImageIcon(HomePage.class.getResource("jf.jpg"));
					JLabel jLabel = new JLabel(icon);
					jLabel.setBounds(0,0,645,900);
					jPanel3.add(jLabel,-1);
					jPanel3.repaint();
					jPanel3.revalidate();
				}
			}
		});
		jPanel2.add(myJLabel);
		// 刷新页面
		jFrame.add(jPanel3, 0);
		jFrame.repaint();
		jFrame.revalidate();
	}
}
